package com.juzipi.demo.tools;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
        //标志
        private Boolean flag;
        //状态码
        private Integer code;
        //返回信息
        private String message;
        //返回数据
        private Object data;


    /**
     * 成功返回值
     * @param data
     * @return
     */
    public static Result successData(Object data){
        return new Result(true,200,"SUCCESS", data);
    }


    /**
     * 成功返回值自定义消息
     * @param data
     * @return
     */
    public static Result success(String message,Object data){
        return new Result(true,200,message, data);
    }


    public static Result success(){
        return new Result(true,200,"SUCCESS",null);
    }


    /**
     * 失败无返回值
     * @param code
     * @return
     */
    public static Result fail(Integer code){
        return new Result(false,code,"ERROR", null);
    }


    /**
     * 失败自定义状态码，消息
     * @param code
     * @return
     */
    public static Result fail(Integer code,String message){
        return new Result(false,code,message,null);
    }



    public static Result fail(){
        return new Result(false,404,"NOT_FOUND", null);
    }


    public static Result successMessage(String message) {
        return new Result(true,200,message,null);
    }
}
